package com.ruoyi.workload.service.impl;

import com.ruoyi.workload.domain.entity.WorkLoad;
import com.ruoyi.workload.domain.entity.WorkLoadTimeList;
import com.ruoyi.workload.mapper.WorkLoadMapper;
import com.ruoyi.workload.service.WorkLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WorkLoadServiceImpl implements WorkLoadService {

    @Autowired
    WorkLoadMapper workLoadMapper;

    @Override
    public List<WorkLoad> workLoadList() {
        return workLoadMapper.getworkLoadList();
    }

    @Override
    public Map<String,WorkLoadTimeList> getWorkLoadListByIdAndProject(String month, String npi, String project) {
        YearMonth ym=YearMonth.parse("2025-07", DateTimeFormatter.ofPattern("yyyy-MM"));
        LocalDate startDateDate = ym.atDay(1);
        LocalDate endDate = ym.atEndOfMonth();
        long until = startDateDate.until(endDate, ChronoUnit.DAYS);

        List<WorkLoad> workLoadList=  workLoadMapper.getWorkLoadListByIdAndProject(startDateDate.toString(),endDate.toString(),npi,project);
        for (WorkLoad workLoad : workLoadList) {
            System.err.println(workLoad);
        }

        return workLoadListToWorkLoadTimeList(workLoadList,ym,until);
    }

    @Override
    public Map<String,WorkLoadTimeList> workLoadListToWorkLoadTimeList(List<WorkLoad> workLoadList, YearMonth ym, Long until) {
        for (int i = 1; i <= until+1; i++) {
            System.err.println(ym.atDay(i));
        }
        String s="";
        Map<String,WorkLoadTimeList> map=new HashMap<>();
        for (WorkLoad workLoad : workLoadList) {
            s=workLoad.getNpi()+workLoad.getProject()+workLoad.getPhase();
            map.put(s,new WorkLoadTimeList());
        }
        return null;
    }

    public List<WorkLoadTimeList> getWorkLoadTimeListData() {

        return null;
    }


}


